package cn.edu.lingnan.view;

import cn.edu.lingnan.pojo.Competition;
import cn.edu.lingnan.pojo.Student;
import cn.edu.lingnan.servcie.AdminServiceTest;
import cn.edu.lingnan.servcie.CompetitionServiceTest;
import cn.edu.lingnan.servcie.ParticipationServiceTest;
import cn.edu.lingnan.servcie.StudentServiceTest;
import cn.edu.lingnan.service.*;

import java.util.Scanner;

public class main {

    static StudentService studentService = new IStudentService();
    static AdminService adminService = new IAdminService();
    static CompetitionService competitionService = new ICompetitionService();
    static ParticipationService  participationService=new IParticipationService();

    public static void main(String[] args) {

        //大学生竞赛系统主界面
        int choose;
        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("*****大学生竞赛系统******");
            System.out.println("请选择角色登录--学生1--管理员2");
            choose = scanner.nextInt();
            scanner.nextLine(); // 清除输入缓冲区中的换行符


            if (choose == 1) {
                    System.out.print("请输入您的学生id：");
                    int id = scanner.nextInt();
                    scanner.nextLine(); // 清除输入缓冲区中的换行符
                    System.out.print("请输入您的密码：");
                    String password = scanner.nextLine();
                    //学生登录验证
                    Student student=studentService.studentLogin(id,password);
                    if(student!=null) {
                        System.out.println("登录成功！");
                        // 学生端登录界面
                        stuLogin(id);
                    }else {
                        System.out.println("id或密码错误！");
                    }
            } else if (choose == 2) {
                System.out.print("请输入您的用户名：");
                String username = scanner.next();
                scanner.nextLine(); // 清除输入缓冲区中的换行符
                System.out.print("请输入您的密码：");
                String password = scanner.next();
                boolean b=adminService.adminLogin(username,password);
                if(b){
                    System.out.println("登录成功！");
                    // 管理员端登录界面
                    adminLogin();
                }else {
                    System.out.println("用户名或密码错误！");
                }

            } else {
                System.out.println("无效操作，请重新输入！");
            }
        }
    }


    //学生登录界面方法
    public static void stuLogin(int id){
        int choose;
        Scanner scanner = new Scanner(System.in);
        while(true) {
            System.out.println("***欢迎您登录学生端***");
            System.out.println("1、查询个人比赛信息");
            System.out.println("2、查看比赛项目");
            System.out.println("3、参加比赛");
            System.out.println("4、退选比赛");
            System.out.println("5、退出");
            System.out.println("请选择您的操作：");
            choose=scanner.nextInt();
            switch (choose){
                case 1:
                    participationService.findParticipationBySid(id);
                    break;

                case 2:
                    for (Competition c:competitionService.findCompetitionAll()
                         ) {
                        System.out.println(c);
                    }
                    break;

                case 3:
                    int student_id,competition_id;
                    System.out.print("请输入学生id：");
                    student_id=scanner.nextInt();
                    scanner.nextLine(); // 清除输入缓冲区中的换行符
                    System.out.println("请输入比赛项目id：");
                    competition_id=scanner.nextInt();
                    participationService.addParticipation(student_id,competition_id,"");
                    break;

                case 4:
                    System.out.println("请输入你退选的比赛：");
                    int student_id1=scanner.nextInt();
                    boolean b= participationService.delParticipation(student_id1);
                   if(b){
                       System.out.println("退选成功！");
                   }else System.out.println("退选失败！");
                    break;

                case 5:
                    return;

                default:
                    System.out.println("无效的输入，请重新选择！");
            }
        }

    }

    //管理员登录界面方法
    public static void adminLogin(){
        int choose;
        Scanner scanner = new Scanner(System.in);
        while(true){
            System.out.println("***欢迎您登录管理员端***");
            System.out.println("1、查询所有学生个人比赛信息");
            System.out.println("2、查看比赛项目");
            System.out.println("3、添加比赛项目");
            System.out.println("4、删除比赛项目");
            System.out.println("5、修改比赛项目");
            System.out.println("6、为学生比赛打分");//在修改处可打分
            System.out.println("7、退出");
            System.out.println("请选择您的操作：");
            choose=scanner.nextInt();
            switch (choose){
                case 1:
                    participationService.findParticipationAll();
                    break;

                case 2:
                    for (Competition c:competitionService.findCompetitionAll()
                    ) {
                        System.out.println(c);
                    }
                    break;

                case 3:
                    String name,description,start_time,end_time;
                    System.out.print("请输入比赛名字：");
                    name=scanner.next();
                    System.out.print("请输入描述：");
                    description=scanner.next();
                    System.out.print("请输入开始时间：");
                    start_time=scanner.next();
                    System.out.print("请输入结束时间：");
                    end_time=scanner.next();
                    competitionService.addCompetition(new Competition(name,description,start_time,end_time));
                    break;

                case 4:
                    System.out.print("请输入要删除的比赛名字");
                    String name1=scanner.nextLine();
                    competitionService.delCompetitionByName(name1);
                    break;

                case 5:
                    String _name,_description,_start_time,_end_time;
                    System.out.print("请输入比赛名字：");
                    _name=scanner.next();
                    System.out.print("请输入描述：");
                    _description=scanner.next();
                    System.out.print("请输入开始时间：");
                    _start_time=scanner.next();
                    System.out.print("请输入结束时间：");
                    _end_time=scanner.next();
                    competitionService.updateCompetitionById(new Competition(_name,_description,_start_time,_end_time));
                    break;

                case 6:
                    //未完待续
                    break;

                case 7:
                    return;

                default:
                    System.out.println("无效的输入，请重新选择！");
            }

        }
    }

}
